#ifndef SHADOWMESSAGEBOX_H
#define SHADOWMESSAGEBOX_H

#include <QWidget>
#include <QLabel>
#include <QIcon>
#include <QHBoxLayout>
#include <QPushButton>
#include <QHash>
#include <QEventLoop>
#include <QButtonGroup>
#include <QGraphicsDropShadowEffect>
#include "titlebar.h"

class ShadowMessageBox : public QWidget
{
    Q_OBJECT
public:
    enum Icon {
            // keep this in sync with QMessageDialogOptions::Icon
            NoIcon = 0,
            Information = 1,
            Warning = 2,
            Critical = 3,
            Question = 4
        };

    enum StandardButton {
        // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
        NoButton           = 0x00000000,
        Ok                 = 0x00000400,
        Save               = 0x00000800,
        SaveAll            = 0x00001000,
        Open               = 0x00002000,
        Yes                = 0x00004000,
        YesToAll           = 0x00008000,
        No                 = 0x00010000,
        NoToAll            = 0x00020000,
        Abort              = 0x00040000,
        Retry              = 0x00080000,
        Ignore             = 0x00100000,
        Close              = 0x00200000,
        Cancel             = 0x00400000,
        Discard            = 0x00800000,
        Help               = 0x01000000,
        Apply              = 0x02000000,
        Reset              = 0x04000000,
        RestoreDefaults    = 0x08000000,

        FirstButton        = Ok,                // internal
        LastButton         = RestoreDefaults,   // internal

        YesAll             = YesToAll,          // obsolete
        NoAll              = NoToAll,           // obsolete

        Default            = 0x00000100,        // obsolete
        Escape             = 0x00000200,        // obsolete
        FlagMask           = 0x00000300,        // obsolete
        ButtonMask         = ~FlagMask          // obsolete
    };
    typedef StandardButton Button;  // obsolete

    ShadowMessageBox(QWidget* parent = nullptr);
    ShadowMessageBox(const QString &title, const QString &text, ShadowMessageBox::Icon icon,
                     StandardButton button1 = StandardButton::NoButton,
                     StandardButton button2 = StandardButton::NoButton,
                     StandardButton button3 = StandardButton::NoButton, QWidget * parent = nullptr);

    static StandardButton information(QWidget * parent, const QString &title, const QString &text,
                                      StandardButton button1 = StandardButton::Ok,
                                      StandardButton button2 = StandardButton::NoButton,
                                      StandardButton button3 = StandardButton::NoButton);
    static StandardButton critical(QWidget * parent, const QString &title, const QString &text,
                                   StandardButton button1 = StandardButton::Ok,
                                   StandardButton button2 = StandardButton::NoButton,
                                   StandardButton button3 = StandardButton::NoButton);

    void setTitle(const QString& title);

    void setText(const QString& text);

    void setIcon(Icon icon);

    void addButton(StandardButton button);

    void addButton(const QString& text);

    void addButton(QAbstractButton* button);

    int exec();

signals:
    void signal_buttonClicked(QAbstractButton* btn);

private:
    StandardButton newButton(int button);

    void addButtons(StandardButton button1, StandardButton button2, StandardButton button3);

    void addAllButton(int button1, int button2, int button3);

    void init(const QString& title = QString(), const QString& text = QString());

    void showEvent(QShowEvent *event) override;

public slots:
    void setClickedButton();

private:
    StandardButton clickedButton();

    bool autoAddOkButton;

    QWidget* m_widg;
    QWidget* m_btnWidg;
    TitleBar * m_pTitleBar;
    QVBoxLayout *m_pLayout;
    QLabel* m_msgIcon;
    QLabel* m_msgText;
    QHBoxLayout* m_hlabLayout;
    QHBoxLayout* m_hbtnLayout;
    QHBoxLayout* m_hpLayout;
    QPushButton* m_clickedButton;
    QGraphicsDropShadowEffect *m_pEffect;
    QHash<QPushButton*, StandardButton> m_buttonHash;
    QEventLoop* eventLoop;
    QButtonGroup* m_btnGroup;
};
// TODO 2022-5-7 能够自定义按钮的内容以及点击按钮的返回值
#endif // SHADOWMESSAGEBOX_H
